import { GITEE_PAGINATION_CONFIG } from '../../../../../lib/page_handler/platform/gitee/types'
import { HOSTNAME, SUPPORTED_PLATFORMS } from '../../../../../types/constants'
import { IPaginationLoadType } from '../index'
import { AutoPaginationBase } from './base'

export enum GiteeSearchParams {
  Page = 'page',
}
export interface IGiteeUrlParams {
  [GiteeSearchParams.Page]: string
}

export class AutoPaginationGitee extends AutoPaginationBase {
  // @Decorators.Identity
  readonly name: string = 'AutoPaginationGitee'
  // @Decorators.PublicState
  private static instance: AutoPaginationGitee
  // @Decorators.Config
  readonly loadType: IPaginationLoadType = IPaginationLoadType.Pagination
  readonly defaultUrlParams: IGiteeUrlParams = { // 搜索链接默认参数值
    [GiteeSearchParams.Page]: '1',
  }

  /**
   * 获取单例实例
   */
  public static getInstance(): AutoPaginationGitee {
    if (!AutoPaginationGitee.instance) {
      AutoPaginationGitee.instance = new AutoPaginationGitee()
    }
    return AutoPaginationGitee.instance
  }

  /**
   * 检查页面
   */
  checkPage(): boolean {
    return HOSTNAME === SUPPORTED_PLATFORMS.GITEE
  }

  /**
   * 从分页元素中获取最大页码数
   */
  getMaxPageNumFromPagination(): number {
    return this.clacMaxPageNum(GITEE_PAGINATION_CONFIG.selector.item)
  }
}
